package logic

import (
	"baidu/baidurpc/baidurpc"
	"context"

	"baidu/api/internal/svc"
	"baidu/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type BookLikeLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewBookLikeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *BookLikeLogic {
	return &BookLikeLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *BookLikeLogic) BookLike(req *types.BookLikeRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line

	register, err := l.svcCtx.BaiDu.BookLike(l.ctx, &baidurpc.BookLikeRequest{
		UserId: req.UserId,
		BookId: req.BookId,
	})
	if err != nil {
		return &types.Response{
			Message: "点赞失败",
			Code:    500,
			Data:    nil,
		}, nil
	}
	return &types.Response{
		Message: "点赞成功",
		Code:    200,
		Data:    register,
	}, nil
}
